<template>
  <div class="app-container">
    <div style="padding-bottom: 10px;">
      <el-button type="primary" @click="openCollect">收藏</el-button>
    </div>

    <el-table
      ref="multipleTable"
      :data="tableData"
      border
      class="table"
      header-cell-class-name="table-header"
    >
      <el-table-column label="名称">
        <template scope="scope">
          <el-link :href="scope.row.url" target="_blank" :underline="false">{{ scope.row.name }}</el-link>
        </template>
      </el-table-column>
    </el-table>

    <div style="text-align: center;">
      <el-pagination
        small
        layout="prev, pager, next"
        :total="total"
        @current-change="handleCurrentChange"
      />
    </div>

    <el-dialog title="收藏" :visible.sync="dialogFormVisible" width="90%">
      <el-form :model="form">
        <el-form-item label="名称">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="地址">
          <el-input v-model="form.url" autocomplete="off"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="collectCreate">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "collect",
  data() {
    return {
      tableData: [],
      total: 0,
      searchFrom: {
        page: 1,
        pageSize: 10,
      },
      form:{
        name:"",
        url:""
      },
      dialogFormVisible:false,
    }
  },
  computed: {

  },
  created() {
    this.collectList()
  },
  methods: {
    collectList() {
      axios.get('/user/collectList', {
        params: {
          page: this.searchFrom.page,
          pageSize: this.searchFrom.pageSize,
        }
      })
        .then((response) => {
          if (response.data.code == 0) {
            this.tableData = response.data.data
            this.total = response.data.count
          }
        })
        .catch(function (error) {
          console.log(error)
        })
    },
    collectCreate(){
      axios.get('/user/collectCreate', {
        params: {
          name:this.form.name,
          url:this.form.url
        }
      })
        .then((response) => {
          if (response.data.code == 0) {
            this.dialogFormVisible = false
            this.collectList()
          }
        })
        .catch(function (error) {
          console.log(error)
        })
    },
    handleCurrentChange(val) {
      this.searchFrom.page = val
      this.collectList()
    },
    openCollect(){
      this.dialogFormVisible = true
    }
  }
}
</script>

<style scoped>

</style>
